package be.novelfaces.component.webdriver;

import org.openqa.selenium.By;

import be.novelfaces.showcase.webdriver.util.WaitForElementPresent;
import be.novelfaces.webdriver.BaseComponent;

public class SourcePanel extends BaseComponent {

	private By togglerId;
	private By contentId;
	private By headerId;
	private By collapsedId;

	public SourcePanel(String id) {
		super(By.id(id + ":panel"));
		this.togglerId = By.id(id + ":panel_toggler");
		this.contentId = By.id(id + ":panel_content");
		this.headerId = By.id(id + ":panel_header");
		this.collapsedId = By.id(id + ":panel_collapsed");
	}

	public void toggle() {
		getWebDriver().findElement(togglerId).click();
		new WaitForElementPresent() {
			@Override
			public By getBy() {
				return contentId;
			}
		};
	}
	
	public boolean isCollapsed() {
		return getWebDriver().findElement(collapsedId).getAttribute("value").equals("true");
	}

	public boolean containsContent(String content) {
		return getWebDriver().findElement(contentId).getText()
				.contains(content);
	}

	public String getHeader() {
		return getWebDriver().findElement(headerId)
				.findElement(By.className("ui-panel-title")).getText();
	}

}
